package com.bwie.order.service.impl;

import com.bwie.common.utils.R;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.common.utils.PageUtils;
import com.bwie.common.utils.Query;

import com.bwie.order.dao.OrderDao;
import com.bwie.order.entity.OrderEntity;
import com.bwie.order.service.OrderService;


@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderDao, OrderEntity> implements OrderService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String orderType = (String) params.get("orderType");
        QueryWrapper<OrderEntity> w = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(orderType)){
            w.eq("order_type",orderType);
        }
        IPage<OrderEntity> page = this.page(
                new Query<OrderEntity>().getPage(params),
                w
        );

        return new PageUtils(page);
    }

    @Override
    public R recordList(Map<String, Object> params, String brokerId) {
        QueryWrapper<OrderEntity> w = new QueryWrapper<>();
        w.eq("broker_id",brokerId);
        List<OrderEntity> entities = baseMapper.selectList(w);
        if (entities!=null){
            String orderType = (String) params.get("orderType");
            if (StringUtils.isNotEmpty(orderType)){
                w.eq("order_type",orderType);
            }
            IPage<OrderEntity> page = this.page(
                    new Query<OrderEntity>().getPage(params),
                    w
            );
            return R.ok().put("page",page);
        }
        return R.error();
    }

}